﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ExameRegister.Model;
using System.Collections.ObjectModel;

namespace ExameRegister
{
    public partial class PositionWindow : ChildWindow
    {
        public PositionWindow(int id)
        {
            InitializeComponent();
             ServiceUtility su = new ServiceUtility();
             su.OnCompletedCallService += new EventHandler<WCFEvent>(su_OnCompletedCallService);
            su.CallService("ExameRegister.BO.LoginBO", "GetPublicOfficialSelection", new object[] { "p.ID=" + id }, this, "position");
            //if (entity.IsXDJL == true)
            //{
            //    tbType.Text = "选调交流";
            //}
            //else if (entity.IsJZXXB)
            //{
            //    tbType.Text = "竞争性选拔";
            //}
            //this.DataContext = entity;
        }

        void su_OnCompletedCallService(object sender, WCFEvent e)
        {
            string tag = e.UserState as string;
            if (string.IsNullOrEmpty(tag))
                return;
            switch (tag)
            {
                case "position":
                    SetPosition(e.Result);                    
                    break;
            }
        }
        void SetPosition(string result)
        {
            ObservableCollection<PublicOfficialSelection> position = Utility.ConvertFromJson<ObservableCollection<PublicOfficialSelection>>(result);
            if (position.Count == 1)
            {
                var entity = position[0];
                if (entity.IsXDJL == true)
                {
                    tbType.Text = "选调交流";
                }
                else if (entity.IsJZXXB)
                {
                    tbType.Text = "竞争性选拔";
                }
                this.DataContext = entity;
            }
        }


        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

